﻿using LightCAD.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QdArch.Shapes
{
    /// <summary>
    /// 推拉门
    /// </summary>
    public class NormalWindow : IShape2dProvider
    {
        public ComponentShape2d[] GetShapes(string category)
        {
            var subCategory = WindowCategory.NormalWindow.ToString();
            var list = new List<ComponentShape2d>
            {
                CreateShape(subCategory,"CentralElevatorDoor", nameof(GetShape_中分电梯门), GetShape_中分电梯门, ""),
           };
            return list.ToArray();
        }

        public bool IsSupportCategory(string category)
        {
            return (category == ArchCategory.Window.ToString());
        }
        public ComponentShape2d CreateShape(string subCategory, string name, string funcName, Func<LcParameterSet, List<ICurve2d>> func, string description)
        {
            var displayName = funcName.Substring(funcName.IndexOf("_") + 1);
            return new ComponentShape2d
            {
                Category = ArchCategory.Window.ToString(),
                SubCategory = subCategory,
                Name = name,
                DisplayName = displayName,
                Description = description,
                Generate = func
            };
        }
        public List<ICurve2d> GetShape_中分电梯门(LcParameterSet pset)
        {
            var sc = new Shape2dCreator();

            const double gap = 25;
            const double offset = 30;
            const double recth = 10;
            var w = (double)pset["Width"];
            var th = (double)pset["Thickness"];
            //var isLeft = (bool)pset["IsLeft"];
            var isNear = (bool)pset["IsNear"];

            if (isNear)
            {
                var pL = sc.Point(-w / 2, -th / 2);
                var pR = sc.Point(w / 2, -th / 2);
                sc.DrawLine(pL, pR);
                //left
                sc.DrawPolygon(
                    sc.Point(pL.X - offset, -th / 2 - gap),
                    sc.Point(-offset, -th / 2 - gap),
                    sc.Point(-offset, -th / 2 - gap - recth),
                    sc.Point(pL.X - offset, -th / 2 - gap - recth));
                //right
                sc.DrawPolygon(
                    sc.Point(pR.X + offset, -th / 2 - gap),
                    sc.Point(offset, -th / 2 - gap),
                    sc.Point(offset, -th / 2 - gap - recth),
                    sc.Point(pR.X + offset, -th / 2 - gap - recth));
            }
            else
            {
                var pL = sc.Point(-w / 2, th / 2);
                var pR = sc.Point(w / 2, th / 2);
                sc.DrawLine(pL, pR);
                //left
                sc.DrawPolygon(
                    sc.Point(pL.X - offset, th / 2 + gap),
                    sc.Point(-offset, th / 2 + gap),
                    sc.Point(-offset, th / 2 + gap + recth),
                    sc.Point(pL.X - offset, th / 2 + gap + recth));
                //right
                sc.DrawPolygon(
                    sc.Point(pR.X + offset, th / 2 + gap),
                    sc.Point(offset, th / 2 + gap),
                    sc.Point(offset, th / 2 + gap + recth),
                    sc.Point(pR.X + offset, th / 2 + gap + recth));

            }

            return sc.Curves;
        }


    }
}
